﻿
#define DEMO_ALL //如果不需要更多接口调用示例，可注释此行语句

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net.NetworkInformation;
using System.Net;

namespace LedDemo
{
    public partial class Form1 : Form
    {        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Console.WriteLine("AppDomain.CurrentDomain.SetupInformation.ApplicationBase:\r\n{0}", AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
            Console.WriteLine("");

            /* 初始化jinhan comm库 */
            LedControl.JHCommInit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int res;
            IntPtr hdl = IntPtr.Zero;
            IntPtr ptl = IntPtr.Zero;
            IntPtr pargs = IntPtr.Zero;
            
            /* 本例只为演示功能，更多接口请调用DllImport来获得，千万要注意C#参数和C Dll中的接口要一一对应，否则会找不到函数入口点或调用出错 */
            /* JHCommInit和JHCommDeinit接口可以放在应用程序的初始化和退出时分别调用，且必须调用，否则TCP和UDP不能正常通讯，本例中分别放在Form1_Load和Form1_FormClosed中调用 */

            /* 创建控制卡实例()*/
            res = LedControl.JHCreateInst(ref hdl, 1);
            if (res != LedControl.JR_OK)
            {
                MessageBox.Show("创建控制卡实例失败， 错误代码：" + res);
                return;
            }

            if(LedControl.DEV_COMM == LedControl.DEV_TCP)
            {
                /* 获得TCP的传输接口 */
                res = LedControl.JHCommGetTransportlayer(ref ptl, 0/* 0: tcp; 1: udp; 2: ether; 3:serial port; */);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得传输层接口失败， 错误代码：" + res);
                    return;
                }

                /* 获得通讯参数 */
                res = LedControl.JHCommGetNetArgStruct(ref pargs, "192.168.1.3", 30000, 5000);
                //res = LedControl.JHCommGetSerialportArgStruct(ref pargs, "COM1", 115200, 8, 0, 0, 5000);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得TCP传输层参数失败， 错误代码：" + res);
                    return;
                }
            }
            else if (LedControl.DEV_COMM == LedControl.DEV_UDP)
            {
                res = LedControl.JHCommGetTransportlayer(ref ptl, 1/* 0: tcp; 1: udp; 2: ether; 3:serial port; */);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得传输层接口失败， 错误代码：" + res);
                    return;
                }

                /* 获得通讯参数 */
                res = LedControl.JHCommGetNetArgStruct(ref pargs, "0.0.0.0", 30000, 5000);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得TCP传输层参数失败， 错误代码：" + res);
                    return;
                }
            }
            else if (LedControl.DEV_COMM == LedControl.DEV_PCAP)
            {
                /* 获得EtherNet的传输接口 */
                res = LedControl.JHCommGetTransportlayer(ref ptl, 2/* 0: tcp; 1: udp; 2: ether; 3:serial port; */);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得传输层接口失败， 错误代码：" + res);
                    return;
                }
                
                //GetAdaptersInfo();
                /* 获得通讯参数 */
                byte[] mac = new byte[6];//目标mac先设置为全f，通讯成功后可再查询目标的mac地址
                mac[0] = 0xff;
                mac[1] = 0xff;
                mac[2] = 0xff;
                mac[3] = 0xff;
                mac[4] = 0xff;
                mac[5] = 0xff;
                string source = "";
                NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
                foreach (NetworkInterface adapter in adapters)
                {
                    if ("以太网" == adapter.Name)
                    {//本例中使用有线网卡作为连接网卡，实际使用可根据连接情况自行修改
                        //最终需要的source格式为： "rpcap://\\Device\\NPF_{AC14FBAF-1607-4F4D-92CF-44E4762CC011}"，其中{}内为网卡Id
                        source = "rpcap://\\Device\\NPF_" + adapter.Id;
                        Console.WriteLine(source);
                    }
                }
                if (0 == source.Length)
                {
                    MessageBox.Show("获取网卡Id失败！");
                    return;
                }
                res = LedControl.JHCommGetEtherArgStruct(ref pargs, source, mac, 5000);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得以太网传输层参数失败， 错误代码：" + res);
                    return;
                }
            }
            else if (LedControl.DEV_COMM == LedControl.DEV_SERIALPORT)
            {
                res = LedControl.JHCommGetTransportlayer(ref ptl, 3/* 0: tcp; 1: udp; 2: ether; 3:serial port; */);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得传输层接口失败， 错误代码：" + res);
                    return;
                }

                /* 获得通讯参数 */
                res = LedControl.JHCommGetSerialportArgStruct(ref pargs, "COM1", 115200, 8, 0, 0, 5000);
                if (res != LedControl.JR_OK)
                {
                    LedControl.JHDeleteInst(hdl);
                    MessageBox.Show("获得串口传输层参数失败， 错误代码：" + res);
                    return;
                }
            }
            else
            {
                MessageBox.Show("不支持的通讯方式！");
            }

            /* 为控制卡绑定传输层接口及通讯参数 */
            res = LedControl.JHMountTransportLayer(hdl, ptl, pargs);
            if (res != LedControl.JR_OK)
            {
                LedControl.JHCommReleaseArgStruct(pargs);
                LedControl.JHDeleteInst(hdl);
                MessageBox.Show("挂载传输层接口失败， 错误代码：" + res);
                return;
            }

            /* 释放通讯参数 */
            LedControl.JHCommReleaseArgStruct(pargs);

            if(true)
            {
                /* 调用屏幕操作中的DrawText接口来立即显示一段文本 */
                string text = richTextBox1.Text.ToString();
                res = LedControl.JHDrawText(hdl, 0, 0, 64, 16, 0, text);//注意调用时的宽高值，过小可能导致显示不完整
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawText指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawText指令失败， 错误代码：" + res);
                }
            }
        #if DEMO_ALL   
            /***************************************系统指令开始*********************************/
            if (false)
            {
                /* 调用修改源地址指令，该指令的功能是修改指令中源地址字段所代表的的地址值，具体可参考通讯指令手册，该指令一般没有必要使用,该接口不会进行实际通讯*/
                byte serveridH = 0x12;
                byte serveridL = 0x34;
                ushort serverid = (ushort)((serveridH << 8) | (serveridL << 0));
                res = LedControl.JHChangeInstServerId(hdl, serverid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHChangeInstServerId指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHChangeInstServerId指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用修改相对地址（屏号）指令，该指令用于修改控制卡屏号，并修改示例句柄中的相对地址值 */
                byte group = 0x01;
                byte id    = 0x01;
                ushort gid = (ushort)((group << 8) | (id << 0));
                res = LedControl.JHChangeInstRelativeId(hdl, gid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHChangeInstRelativeId指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHChangeInstRelativeId指令失败， 错误代码：" + res);
                }
            }
           
            if (false)
            {
                
                /* 调用查询相对地址（屏号）指令，该指令用于在不知道控制卡屏号时查询控制卡的屏号 */
                ushort gid = 0;
                res = LedControl.JHGetGID(hdl, ref gid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetGID指令成功:Group = " + ((gid >> 8) & 0xff) + "  ID = " + ((gid >> 0) & 0xff));
                }
                else
                {
                    MessageBox.Show("发送JHGetGID指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 调用配置相对地址（屏号）指令 */
                ushort gid = 0x0101;
                res = LedControl.JHSetGID(hdl, gid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetGID指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetGID指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 调用查询绝对地址(UID，产品ID，唯一，不可修改)指令 */
                byte[] uid = new byte[8];
                res = LedControl.JHGetUID(hdl, uid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetUID指令成功, uid = 0x" + uid[0].ToString("X2") + uid[1].ToString("X2") + uid[2].ToString("X2") + uid[3].ToString("X2") + uid[4].ToString("X2") + uid[5].ToString("X2") + uid[6].ToString("X2") + uid[7].ToString("X2"));
                }
                else
                {
                    MessageBox.Show("发送JHGetUID指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 调用通过UID获取相对地址GID指令，该指令一般不使用，主要用途是群组控制时，事先知道了UID后可查询对应的GID */
                byte[] uid = new byte[8]{0x4A, 0x05, 0x9F, 0x2F, 0xCF, 0xE5, 0x28, 0xA6};
                ushort gid = 0x00;
                res = LedControl.JHGetGIDByUID(hdl, uid, ref gid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetGIDByUID指令成功, Group = " + ((gid >> 8) & 0xff) + "  ID = " + ((gid >> 0) & 0xff));
                }
                else
                {
                    MessageBox.Show("发送JHGetGIDByUID指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 调用通过UID修改相对地址GID指令，该指令一般不使用，主要用途是群组控制时，事先知道了UID后可重新配置对应的GID */
                byte[] uid = new byte[8] { 0x4A, 0x05, 0x9F, 0x2F, 0xCF, 0xE5, 0x28, 0xA6 };
                ushort gid = 0x0101;
                res = LedControl.JHSetGIDByUID(hdl, uid, gid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetGIDByUID指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetGIDByUID指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 调用查询串口参数指令，依次为波特率，数据位，校验位，停止位，流控 */
                uint baudrate = 0;//有效值为9600，14400， 19200， 38400， 560， 57600， 115200
                byte databits = 0;//有效值为8，9
                byte parity = 0;  //有效值为0（无校验） 1（奇校验） 2（偶校验）
                byte stopbits = 0;//有效值为0（1位停止位） 1（1.5位停止位） 2（2位停止位）
                byte flowctrl = 0;//有效职位0（无流控）
                res = LedControl.JHGetSerialAttr(hdl, ref baudrate, ref databits, ref parity, ref stopbits, ref flowctrl);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetSerialAttr指令成功, 波特率 = " + baudrate + "  数据位 = " + databits + "  校验位 = " + parity + "  停止位 = " + stopbits + "  流控 = " + flowctrl);
                }
                else
                {
                    MessageBox.Show("发送JHGetSerialAttr指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 调用配置串口参数指令，依次为波特率，数据位，校验位，停止位，流控 */
                uint baudrate = 115200;//有效值为9600，14400， 19200， 38400， 560， 57600， 115200
                byte databits = 8;//有效值为8，9
                byte parity = 0;  //有效值为0（无校验） 1（奇校验） 2（偶校验）
                byte stopbits = 0;//有效值为0（1位停止位） 1（1.5位停止位） 2（2位停止位）
                byte flowctrl = 0;//有效职位0（无流控）
                res = LedControl.JHSetSerialAttr(hdl, baudrate, databits, parity, stopbits, flowctrl);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetSerialAttr指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetSerialAttr指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 查询TCP服务器端口号指令 */
                ushort port = 0;
                res = LedControl.JHGetPort(hdl, ref port);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetPort指令成功， Port = " + port);
                }
                else
                {
                    MessageBox.Show("发送JHGetPort指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 配置TCP服务器端口号指令 */
                ushort port = 30000;
                res = LedControl.JHSetPort(hdl, port);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetPort指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetPort指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 查询IPv4指令，包含IPCTRL（ip控制参数，具体参见说明文档）， ip地址，子网掩码，默认网关，默认域名服务器，备用域名服务器 */
                uint ipctrl = 0;//0表示自动获取IP，1表示静态IP
                uint ipv4 = 0;
                uint netmask = 0;
                uint defgw = 0;
                uint pridns = 0;
                uint secdns = 0;
                res = LedControl.JHGetIPv4(hdl, ref ipctrl, ref ipv4, ref netmask, ref defgw, ref pridns, ref secdns);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetIPv指令成功, \nipctrl = " + ipctrl + "  \nipv4:" + ((ipv4 >> 0) & 0xff) + "." + ((ipv4 >> 8) & 0xff) + "." + ((ipv4 >> 16) & 0xff) + "." + ((ipv4 >> 24) & 0xff) +
                        "  \nnetmask:" + ((netmask >> 0) & 0xff) + "." + ((netmask >> 8) & 0xff) + "." + ((netmask >> 16) & 0xff) + "." + ((netmask >> 24) & 0xff) +
                        "  \ndefgw:" + ((defgw >> 0) & 0xff) + "." + ((defgw >> 8) & 0xff) + "." + ((defgw >> 16) & 0xff) + "." + ((defgw >> 24) & 0xff) +
                        "  \npridns:" + ((pridns >> 0) & 0xff) + "." + ((pridns >> 8) & 0xff) + "." + ((pridns >> 16) & 0xff) + "." + ((pridns >> 24) & 0xff) +
                        "  \nsecdns:" + ((secdns >> 0) & 0xff) + "." + ((secdns >> 8) & 0xff) + "." + ((secdns >> 16) & 0xff) + "." + ((secdns >> 24) & 0xff)
                    );
                }
                else
                {
                    MessageBox.Show("发送JHGetIPv指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 配置IPv4指令，包含IPCTRL（ip控制参数，具体参见说明文档）， ip地址，子网掩码，默认网关，默认域名服务器，备用域名服务器 */
                uint ipctrl = 1;//0表示自动获取IP，1表示静态IP
                uint ipv4 = ((192 << 0) | (168 << 8) | (1 << 16) | (3 << 24));
                uint netmask = (255 << 0) | (255 << 8) | (255 << 16) | (0 << 24);
                uint defgw = ((192 << 0) | (168 << 8) | (1 << 16) | (1 << 24));
                uint pridns = ((202 << 0) | (102 << 8) | (192 << 16) | (68 << 24));
                uint secdns = ((202 << 0) | (102 << 8) | (199 << 16) | (68 << 24));
                res = LedControl.JHSetIPv4(hdl, ipctrl, ipv4, netmask, defgw, pridns, secdns);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetIPv4指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetIPv4指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {

                /* 调用查询MAC地址指令 */
                byte[] mac = new byte[6];
                res = LedControl.JHGetMac(hdl, mac);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetMac指令成功, mac:" + mac[0].ToString("X2") + "-" + mac[1].ToString("X2") + "-" + mac[2].ToString("X2") + "-" + mac[3].ToString("X2") + "-" + mac[4].ToString("X2") + "-" + mac[5].ToString("X2"));
                }
                else
                {
                    MessageBox.Show("发送JHGetMac指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {                
                /* 调用查询屏宽屏高指令 */
                ushort width = 0;
                ushort height = 0;
                res = LedControl.JHGetLedSize(hdl, ref width, ref height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetLedSize指令成功，宽度 = " + width +  "  高度 = " + height);
                }
                else
                {
                    MessageBox.Show("发送JHGetLedSize指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置屏宽屏高指令 */
                ushort width = 64;
                ushort height = 32;
                res = LedControl.JHSetLedSize(hdl, width, height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetLedSize指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetLedSize指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询默认单元板参数指令 */
                LedControl.JHLEDMODULE ledmodule;
                byte[] ptrack = new byte[4096];//大小不能确定，可以弄一个比较大的，不一定会使用到
                ledmodule.lmScanDirection = 0;
                ledmodule.lmColor = 0;
                ledmodule.lmScan = 0;
                ledmodule.lmOSR = 0;
                ledmodule.lmOSC = 0;
                ledmodule.lmRowDecode = 0;
                ledmodule.lmPolar = 0;
                ledmodule.lmClockPhase = 0;
                ledmodule.lmLatchPhase = 0;
                ledmodule.lmData = 0;
                ledmodule.lmReserve = new byte[6];
                ledmodule.lmTrackMode = 0;
                ledmodule.lmTrackSize = 0;
                res = LedControl.JHGetDefLedMod(hdl, ref ledmodule, ptrack);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetDefLedMod指令成功，\n扫描方向     = " + ledmodule.lmScanDirection + 
                        "  \n颜色         = " + ledmodule.lmColor + 
                        "  \n扫描         = " + ledmodule.lmScan + 
                        "  \n每区扫描行数 = " + ledmodule.lmOSR + 
                        "  \n每区扫描列数 = " + ledmodule.lmOSC + 
                        "  \n行译码       = " + ledmodule.lmRowDecode + 
                        "  \n极性         = " + ledmodule.lmPolar + 
                        "  \n时钟相位     = " + ledmodule.lmClockPhase + 
                        "  \n锁存相位     = " + ledmodule.lmLatchPhase + 
                        "  \n数据组织     = " + ledmodule.lmData + 
                        "  \n走线路径     = " + ledmodule.lmTrackMode + 
                        "  \n扫描路径大小 = " + ledmodule.lmTrackSize);
                }
                else
                {
                    MessageBox.Show("发送JHGetDefLedMod指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置默认单元板参数指令 */
                LedControl.JHLEDMODULE ledmodule;
                byte[] ptrack = new byte[4096];//大小不能确定，可以弄一个比较大的，不一定会使用到
                ledmodule.lmScanDirection = 0; //0 正常  1镜像
                ledmodule.lmColor = 0;//0单色  1双色 2 彩色
                ledmodule.lmScan = 16;//扫描，一般为1-16，也有32扫的
                ledmodule.lmOSR = 1;//每区扫描行数，与单元板电路有关系
                ledmodule.lmOSC = 8;//每区扫描列数，与单元板电路有关系
                ledmodule.lmRowDecode = 0;//0138译码，1ABCD直译，由单元板电路决定
                ledmodule.lmPolar = 7;//bit0：时钟极性  bit1：锁存极性 bit2：OE极性 bit3：数据极性
                ledmodule.lmClockPhase = 0;//时钟相位，暂无用处
                ledmodule.lmLatchPhase = 0;//锁存相位，暂无用处
                ledmodule.lmData = 0;//数据组织，暂无用处
                ledmodule.lmReserve = new byte[6];//保留，暂无用处
                ledmodule.lmTrackMode = 1;//走线路径，Z型以右上角为起点
                ledmodule.lmTrackSize = 0;//自定义扫描路径大小，0
                res = LedControl.JHSetDefLedMod(hdl, ref ledmodule, ptrack);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetDefLedMod指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetDefLedMod指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询当前单元板参数指令 */
                LedControl.JHLEDMODULE ledmodule;
                byte[] ptrack = new byte[4096];//大小不能确定，可以弄一个比较大的，不一定会使用到
                ledmodule.lmScanDirection = 0;
                ledmodule.lmColor = 0;
                ledmodule.lmScan = 0;
                ledmodule.lmOSR = 0;
                ledmodule.lmOSC = 0;
                ledmodule.lmRowDecode = 0;
                ledmodule.lmPolar = 0;
                ledmodule.lmClockPhase = 0;
                ledmodule.lmLatchPhase = 0;
                ledmodule.lmData = 0;
                ledmodule.lmReserve = new byte[6];
                ledmodule.lmTrackMode = 0;
                ledmodule.lmTrackSize = 0;
                res = LedControl.JHGetCurLedMod(hdl, ref ledmodule, ptrack);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetCurLedMod指令成功，\n扫描方向     = " + ledmodule.lmScanDirection +
                        "  \n颜色         = " + ledmodule.lmColor +
                        "  \n扫描         = " + ledmodule.lmScan +
                        "  \n每区扫描行数 = " + ledmodule.lmOSR +
                        "  \n每区扫描列数 = " + ledmodule.lmOSC +
                        "  \n行译码       = " + ledmodule.lmRowDecode +
                        "  \n极性         = " + ledmodule.lmPolar +
                        "  \n时钟相位     = " + ledmodule.lmClockPhase +
                        "  \n锁存相位     = " + ledmodule.lmLatchPhase +
                        "  \n数据组织     = " + ledmodule.lmData +
                        "  \n走线路径     = " + ledmodule.lmTrackMode +
                        "  \n扫描路径大小 = " + ledmodule.lmTrackSize);
                }
                else
                {
                    MessageBox.Show("发送JHGetCurLedMod指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置当前单元板参数指令 */
                LedControl.JHLEDMODULE ledmodule;
                byte[] ptrack = new byte[4096];//大小不能确定，可以弄一个比较大的，不一定会使用到
                ledmodule.lmScanDirection = 0; //0 正常  1镜像
                ledmodule.lmColor = 0;//0单色  1双色 2 彩色
                ledmodule.lmScan = 16;//扫描，一般为1-16，也有32扫的
                ledmodule.lmOSR = 1;//每区扫描行数，与单元板电路有关系
                ledmodule.lmOSC = 8;//每区扫描列数，与单元板电路有关系
                ledmodule.lmRowDecode = 0;//0138译码，1ABCD直译，由单元板电路决定
                ledmodule.lmPolar = 7;//bit0：时钟极性  bit1：锁存极性 bit2：OE极性 bit3：数据极性
                ledmodule.lmClockPhase = 0;//时钟相位，暂无用处
                ledmodule.lmLatchPhase = 0;//锁存相位，暂无用处
                ledmodule.lmData = 0;//数据组织，暂无用处
                ledmodule.lmReserve = new byte[6];//保留，暂无用处
                ledmodule.lmTrackMode = 1;//走线路径，Z型以右上角为起点
                ledmodule.lmTrackSize = 0;//自定义扫描路径大小，0
                res = LedControl.JHSetCurLedMod(hdl, ref ledmodule, ptrack);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetCurLedMod指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetCurLedMod指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询扫描频率指令 */
                ushort refreq = 0;
                res = LedControl.JHGetDefRefreq(hdl, ref refreq);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetDefRefreq指令成功，扫描频率 = " + refreq);
                }
                else
                {
                    MessageBox.Show("发送JHGetDefRefreq指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置扫描频率指令 */
                ushort refreq = 400;
                res = LedControl.JHSetDefRefreq(hdl, refreq);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetDefRefreq指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetDefRefreq指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询默认亮度指令 */
                ushort lum = 0;
                res = LedControl.JHGetDefLum(hdl, ref lum);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetDefLum指令成功，默认亮度 = " + lum);
                }
                else
                {
                    MessageBox.Show("发送JHGetDefLum指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置默认亮度指令 */
                ushort lum = 500;
                res = LedControl.JHSetDefLum(hdl, lum);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetDefLum指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetDefLum指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询当前亮度指令 */
                ushort lum = 0;
                res = LedControl.JHGetCurLum(hdl, ref lum);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetCurLum指令成功，当前亮度 = " + lum);
                }
                else
                {
                    MessageBox.Show("发送JHGetCurLum指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置当前亮度指令 */
                ushort lum = 500;
                res = LedControl.JHSetCurLum(hdl, lum);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetCurLum指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetCurLum指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询默认字库ID指令 */
                byte fid = 0;
                res = LedControl.JHGetDefFont(hdl, ref fid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetDefFont指令成功，默认字库ID = " + fid);
                }
                else
                {
                    MessageBox.Show("发送JHGetDefFont指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置默认字库ID指令 */
                byte fid = 1;
                res = LedControl.JHSetDefFont(hdl, fid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetDefFont指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetDefFont指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询当前（临时）字库ID指令 */
                byte fid = 0;
                res = LedControl.JHGetCurFont(hdl, ref fid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetCurFont指令成功，当前字库ID = " + fid);
                }
                else
                {
                    MessageBox.Show("发送JHGetCurFont指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置当前（临时）字库ID指令 */
                byte fid = 1;
                res = LedControl.JHSetCurFont(hdl, fid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetCurFont指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetCurFont指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询默认颜色指令 */
                uint color = 0;
                res = LedControl.JHGetDefPenColor(hdl, ref color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetDefPenColor指令成功，默认颜色 = " + color.ToString("X8"));
                }
                else
                {
                    MessageBox.Show("发送JHGetDefPenColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置默认颜色指令 */
                uint color = 0x07;
                res = LedControl.JHSetDefPenColor(hdl, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetDefPenColor指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetDefPenColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询当前（临时）颜色指令 */
                uint color = 0;
                res = LedControl.JHGetCurPenColor(hdl, ref color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetCurPenColor指令成功，当前颜色 = " + color.ToString("X8"));
                }
                else
                {
                    MessageBox.Show("发送JHGetCurPenColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置当前（临时）颜色指令 */
                uint color = 0x07;
                res = LedControl.JHSetCurPenColor(hdl, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetCurPenColor指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetCurPenColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询默认画刷颜色指令 */
                uint color = 0;
                res = LedControl.JHGetDefBrushColor(hdl, ref color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetDefBrushColor指令成功，默认画刷颜色 = " + color.ToString("X8"));
                }
                else
                {
                    MessageBox.Show("发送JHGetDefBrushColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置默认画刷颜色指令 */
                uint color = 0x07;
                res = LedControl.JHSetDefBrushColor(hdl, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetDefBrushColor指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetDefBrushColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询当前（临时）画刷颜色指令 */
                uint color = 0;
                res = LedControl.JHGetCurBrushColor(hdl, ref color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetCurBrushColor指令成功，当前画刷颜色 = " + color.ToString("X8"));
                }
                else
                {
                    MessageBox.Show("发送JHGetCurBrushColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置当前（临时）画刷颜色指令 */
                uint color = 0x07;
                res = LedControl.JHSetCurBrushColor(hdl, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetCurBrushColor指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetCurBrushColor指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询区域语言指令 */
                ushort locale = 0;//437英文 936简体中文 950繁体中文
                res = LedControl.JHGetLocale(hdl, ref locale);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetLocale指令成功，区域语言 = " + locale);
                }
                else
                {
                    MessageBox.Show("发送JHGetLocale指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询系统时间指令 */
                LedControl.JHSYSTEMTIME time;
                time.wYear = 0;
                time.wMonth = 0;
                time.wDay = 0;
                time.wHour = 0;
                time.wMinute = 0;
                time.wSecond = 0;
                time.wMilliseconds = 0;//实际不管是读取还是写入，都按0来算，不会精确到毫秒。
                time.wDayOfWeek = 0;//0是星期日，1是星期一...
                res = LedControl.JHGetSystemTime(hdl, ref time);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetSystemTime指令成功，系统时间 = " + 
                        time.wYear + "-" + time.wMonth + "-" + time.wDay + " " + 
                        time.wHour + ":" + time.wMinute + ":" + time.wSecond + "::" + time.wMilliseconds +  " 星期" +
                        time.wDayOfWeek);
                }
                else
                {
                    MessageBox.Show("发送JHGetSystemTime指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置系统时间指令 */
                LedControl.JHSYSTEMTIME time;
                time.wYear = 2020;
                time.wMonth = 7;
                time.wDay = 31;
                time.wHour = 6;
                time.wMinute = 20;
                time.wSecond = 30;
                time.wMilliseconds = 123; ;//实际不管是读取还是写入，都按0来算，不会精确到毫秒。
                time.wDayOfWeek = 5;//0是星期日，1是星期一.
                res = LedControl.JHSetSystemTime(hdl, ref time);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetSystemTime指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetSystemTime指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询系统版本号指令 */
                uint hwver = 0;//硬件版本号，每一种型号的卡硬件版本号相同，不同型号的卡硬件版本号不同。
                uint swver = 0;//控制卡芯片内部的应用程序的版本号。
                res = LedControl.JHGetSystemVersion(hdl, ref hwver, ref swver);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetSystemVersion指令成功" + 
                        "  \n硬件版本号 = 0x" + hwver.ToString("X8") + 
                        "  \n软件版本号 = 0x" + swver.ToString("X8"));
                }
                else
                {
                    MessageBox.Show("发送JHGetSystemVersion指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询存储器剩余空间指令 */
                uint capacity = 0;//单位字节
                res = LedControl.JHGetRestCapacity(hdl, ref capacity);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetRestCapacity指令成功" +
                        "  \n容量 = " + capacity + "字节" +
                        "  \n容量 = " + capacity/1024 + "KB" + 
                        "  \n容量 = " + (capacity*1.0/1024/1024).ToString("F2") + "MB");
                }
                else
                {
                    MessageBox.Show("发送JHGetRestCapacity指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询存储器总的存储空间指令 */
                uint capacity = 0;//单位字节
                res = LedControl.JHGetTotalCapacity(hdl, ref capacity);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetTotalCapacity指令成功" +
                        "  \n容量 = " + capacity + "字节" +
                        "  \n容量 = " + capacity / 1024 + "KB" +
                        "  \n容量 = " + (capacity * 1.0 / 1024 / 1024).ToString("F2") + "MB");
                }
                else
                {
                    MessageBox.Show("发送JHGetTotalCapacity指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询静默模式指令 */
                byte silentmode = 0;//开启静默模式后，发送给控制卡的指令，绝大部分控制卡只处理，不作数据回应，个别几个指令才回应，具体是哪些指令参见参考手册
                                    //该模式主要应用于485多屏连接且频繁发送数据时
                res = LedControl.JHGetSilentMode(hdl, ref silentmode);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetSilentMode指令成功，静默模式 = " + silentmode);
                }
                else
                {
                    MessageBox.Show("发送JHGetSilentMode指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用配置静默模式指令 */
                byte silentmode = 0;//开启静默模式后，发送给控制卡的指令，绝大部分控制卡只处理，不作数据回应，个别几个指令才回应，具体是哪些指令参见参考手册
                                    //该模式主要应用于485多屏连接且频繁发送数据时
                                    //一般使用建议不要开启，设置为1表示开启。
                res = LedControl.JHSetSilentMode(hdl, silentmode);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSetSilentMode指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSetSilentMode指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用控制开机关机指令 */
                byte onoff = 0;//0表示关机，1表示开机，注意关机指令发送后(如果当前是关机状态，该指令会范围错误码53，表示控制卡已经关机)
                res = LedControl.JHPower(hdl, onoff);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHPower指令成功：关机");
                }
                else
                {
                    MessageBox.Show("发送JHPower指令失败， 错误代码：" + res);
                }

                onoff = 1;//0表示关机，1表示开机，注意开机指令发送后(如果当前是开机状态，该指令会范围错误码52，表示控制卡已经开机)，控制卡会重新启动，启动一般需要几秒的时间，不同型号的控制卡开机时间不同
                res = LedControl.JHPower(hdl, onoff);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHPower指令成功：开机");
                }
                else
                {
                    MessageBox.Show("发送JHPower指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用重启指令 */
                //重启需要几秒的时间，这个过程中是通讯不上的，不同型号的控制卡重启时间不同。
                res = LedControl.JHRestart(hdl);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHRestart指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHRestart指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用升级指令 */
                //升级分三大步，三个接口，按顺序调用，示例中升级文件(../../../../res/update.bin)为一个无用文件，发送过去后，系统有升级过程，但最终不会升级
                IntPtr fd = IntPtr.Zero;//仅用于dll库内部使用
                uint writesize = 0;//升级文件所占字节数
                uint woffset = 0;//升级操作第二大步需要分包发送，该值为每个包的起始处相对于总文件起始处的字节偏移值
                uint size = 1024;//升级操作第二大步需要分包发送，该值为没个包数据长度，注意最后一个包长度可能不足1024
                //byte[] pdata = new byte[size];//size大小为1024，也可自定义，但不要超过1200
                BinaryReader br;
                FileInfo fileinfo = new FileInfo("../../../../res/update.bin");
                uint i;
                byte byteH;
                byte byteL;
                byte byteValue;
                
                writesize = (uint)(fileinfo.Length);
                try
                {
                    br = new BinaryReader(new FileStream("../../../../res/update.bin", FileMode.Open));
                }
                catch (IOException ep)
                {
                    MessageBox.Show(ep.Message + "\n Cannot open file: updata.bin");
                    goto FLAG_END;
                }

                byte[] pfiledata = br.ReadBytes((int)writesize);
                br.Close();
                writesize /= 2;
                byte[] pdata = new byte[writesize];
                //升级文件需要做一个转换
                for (i = 0; i < writesize; i++)
                {
                    byteH = pfiledata[i * 2 + 0];
                    byteL = pfiledata[i * 2 + 1];

                    byteValue = 0;

                    if ( (byteH >= '0') && (byteH <= '9') )
                    {
                        byteValue = (byte)((byteH - '0') << 4);
                    }
                    else if( (byteH >= 'a') && (byteH <= 'f') )
                    {
                        byteValue = (byte)((byteH - 'a' + 10) << 4);
                    }
                    else if( (byteH >= 'A') && (byteH <= 'F') )
                    {
                        byteValue = (byte)((byteH - 'A' + 10) << 4);
                    }

                    if ((byteL >= '0') && (byteL <= '9'))
                    {
                        byteValue += (byte)((byteL - '0') << 0);
                    }
                    else if ((byteL >= 'a') && (byteL <= 'f'))
                    {
                        byteValue += (byte)((byteL - 'a' + 10) << 0);
                    }
                    else if ((byteL >= 'A') && (byteL <= 'F'))
                    {
                        byteValue += (byte)((byteL - 'A' + 10) << 0);
                    }

                    pdata[i] = byteValue;
                }

                res = LedControl.JHPreUpgrade(hdl, ref fd, writesize);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHPreUpgrade指令成功， 文件大小：" + writesize);
                }
                else
                {
                    MessageBox.Show("发送JHPreUpgrade指令失败， 错误代码：" + res);
                    goto FLAG_END;
                }
                
                for (woffset = 0; woffset < writesize; woffset += size)
                {
                    if (woffset + size > writesize)
                    {
                        size = writesize - woffset;
                    }

                    res = LedControl.JHWriteUpgrade(hdl, fd, woffset, pdata.Skip((int)woffset).Take((int)size).ToArray(), size);
//                    for (i = 0; i < size; i++)
//                    {
//                        Console.Write(pdata[woffset + i].ToString("X2"));
//                    }
//                    Console.Write("\n");
                    if (res == LedControl.JR_OK)
                    {
                        //MessageBox.Show("发送JHWriteUpgrade指令成功");
                    }
                    else
                    {
                        MessageBox.Show("发送JHWriteUpgrade指令失败， 错误代码：" + res);
                        goto FLAG_END;
                    }
                }
            FLAG_END:
                res = LedControl.JHFinUpgrade(hdl, fd);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFinUpgrade指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHFinUpgrade指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用参数恢复出厂指令 */
                //注意参数恢复出厂后通讯配置的变化。
                res = LedControl.JHRestoreFactory(hdl);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHRestoreFactory指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHRestoreFactory指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用系统恢复出厂指令 */
                //注意系统恢复出厂后，参数也会恢复出厂，注意通讯配置的变化，且指令调用成功后，执行较慢，可能要等待1分钟左右系统会自动重启。
                res = LedControl.JHRestoreSysFactory(hdl);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHRestoreSysFactory指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHRestoreSysFactory指令失败， 错误代码：" + res);
                }
            }

            /***************************************系统指令结束*********************************/


            /***************************************字库指令开始*********************************/

            if (false)
            {
                /* 调用查询字体数量指令 */
                byte cnt = 0;
                res = LedControl.JHGetFontCnt(hdl, ref cnt);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetFontCnt指令成功，字体个数 = " + cnt);
                }
                else
                {
                    MessageBox.Show("发送JHGetFontCnt指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询字体ID指令 */
                //字体的序号跟字体ID是没有关系的，字体需要是从0开始的，字体ID是从1开始的。
                byte index = 0;
                byte fid = 0;
                res = LedControl.JHGetFontId(hdl, index, ref fid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetFontId指令成功，第" + (index + 1) + "字体的ID = " + fid);
                }
                else
                {
                    MessageBox.Show("发送JHGetFontId指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询字体信息指令 */
                //字体的序号跟字体ID是没有关系的，字体需要是从0开始的，字体ID是从1开始的。
                byte fid = 1;
                LedControl.JHLOGFONT logfont;
                logfont.lfHeight = 0;
                logfont.lfWidth = 0;
                logfont.lfEscapement = 0;
                logfont.lfOrientation = 0;
                logfont.lfWeight = 0;
                logfont.lfItalic = 0;
                logfont.lfUnderline = 0;
                logfont.lfStrikeOut = 0;
                logfont.lfCharSet = 0;
                logfont.lfOutPrecision = 0;
                logfont.lfClipPrecision = 0;
                logfont.lfQuality = 0;
                logfont.lfPitchAndFamily = 0;
                logfont.lfFaceName = new byte[32];
                res = LedControl.JHGetFontInfo(hdl, fid, ref logfont);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetFontInfo指令成功，\n字体ID = " + fid + " 的字体信息如下："  +
                        "  \nlfHeight         = " + logfont.lfHeight + 
                        "  \nlfWidth          = " + logfont.lfWidth + 
                        "  \nlfEscapement     = " + logfont.lfEscapement + 
                        "  \nlfOrientation    = " + logfont.lfOrientation + 
                        "  \nlfWeight         = " + logfont.lfWeight + 
                        "  \nlfItalic         = " + logfont.lfItalic + 
                        "  \nlfUnderline      = " + logfont.lfUnderline + 
                        "  \nlfStrikeOut      = " + logfont.lfStrikeOut + 
                        "  \nlfCharSet        = " + logfont.lfCharSet + 
                        "  \nlfOutPrecision   = " + logfont.lfOutPrecision + 
                        "  \nlfClipPrecision  = " + logfont.lfClipPrecision + 
                        "  \nlfQuality        = " + logfont.lfQuality + 
                        "  \nlfPitchAndFamily = " + logfont.lfPitchAndFamily + 
                        "  \nlfFaceName       = " + System.Text.Encoding.GetEncoding("GB2312").GetString(logfont.lfFaceName));
                }
                else
                {
                    MessageBox.Show("发送JHGetFontInfo指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询字体是否存在指令 */
                byte fid = 1;
                res = LedControl.JHInquireFont(hdl, fid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHInquireFont指令成功，字体存在！");
                }
                else
                {
                    MessageBox.Show("发送JHInquireFont指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用下载字库指令 */
                //下载分三大步，三个接口，按顺序调用，示例中升级文件(../../../../res/字体1宋体16点阵.zk)为一个用zkled生成的字库文件
                IntPtr fd = IntPtr.Zero;//仅用于dll库内部使用
                byte fid = 2;//字库ID
                uint writesize = 0;//字库文件所占字节数
                uint woffset = 0;//下载操作第二大步需要分包发送，该值为每个包的起始处相对于总文件起始处的字节偏移值
                uint size = 1024;//下载操作第二大步需要分包发送，该值为没个包数据长度，注意最后一个包长度可能不足1024
                //byte[] pdata = new byte[size];//size大小为1024，也可自定义，但不要超过1200
                BinaryReader br;
                FileInfo fileinfo = new FileInfo("../../../../res/字体1宋体16点阵.zk");
                uint i;
                byte byteH;
                byte byteL;
                byte byteValue;

                writesize = (uint)(fileinfo.Length);
                try
                {
                    br = new BinaryReader(new FileStream("../../../../res/字体1宋体16点阵.zk", FileMode.Open));
                }
                catch (IOException ep)
                {
                    MessageBox.Show(ep.Message + "\n Cannot open file: 字体1宋体16点阵.zk");
                    goto FLAG_END;
                }

                byte[] pdata = br.ReadBytes((int)writesize);
                br.Close();

                res = LedControl.JHPreCreateFont(hdl, ref fd, fid, writesize);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHPreCreateFont指令成功， 文件大小：" + writesize);
                }
                else
                {
                    MessageBox.Show("发送JHPreCreateFont指令失败， 错误代码：" + res);
                    goto FLAG_END;
                }

                for (woffset = 0; woffset < writesize; woffset += size)
                {
                    Console.WriteLine("offet = " + woffset);
                    if (woffset + size > writesize)
                    {
                        size = writesize - woffset;
                    }

                    res = LedControl.JHWriteFont(hdl, fd, woffset, pdata.Skip((int)woffset).Take((int)size).ToArray(), size);
                    if (res == LedControl.JR_OK)
                    {
                        //MessageBox.Show("发送JHWriteFont指令成功");
                    }
                    else
                    {
                        MessageBox.Show("发送JHWriteFont指令失败， 错误代码：" + res);
                        goto FLAG_END;
                    }
                }
            FLAG_END:
                res = LedControl.JHFinCreateFont(hdl, fd);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFinCreateFont指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHFinCreateFont指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用删除字库指令 */
                byte fid = 2;
                res = LedControl.JHDeleteFont(hdl, fid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDeleteFont指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDeleteFont指令失败， 错误代码：" + res);
                }
            }

            /***************************************字库指令结束*********************************/


            /***************************************屏幕操作指令开始*********************************/
            
            if (false)
            {
                /* 调用清屏指令 */
                res = LedControl.JHErase(hdl);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHErase指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHErase指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用点亮点组指令 */
                ushort i;
                ushort poscnt = 5;
                ushort[] pdat = new ushort[poscnt*2];
                for (i = 0; i < poscnt; i++)
                {
                    pdat[i * 2 + 0] = i;
                    pdat[i * 2 + 1] = i;
                }
                res = LedControl.JHDrawMultPixel(hdl, pdat, poscnt);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawMultPixel指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawMultPixel指令失败， 错误代码：" + res);
                }
            }
        #if (false)
            //该接口暂无作用
            if (false)
            {
                /* 调用高级点亮点组指令 */
                ushort i;
                ushort poscnt = 10;
                ushort[] pdat = new ushort[poscnt * 2];
                uint color = 0x07;
                for (i = 0; i < poscnt; i++)
                {
                    pdat[i * 2 + 0] = (ushort)(i + 1);
                    pdat[i * 2 + 1] = i;
                }
                res = LedControl.JHDrawMultPixelEx(hdl, pdat, poscnt, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawMultPixelEx指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawMultPixelEx指令失败， 错误代码：" + res);
                }
            }
        #endif
            if (false)
            {
                /* 调用画线指令 */
                short x1 = 0;
                short y1 = 0;
                short x2 = 10;
                short y2 = 10;
                res = LedControl.JHDrawLine(hdl, x1, y1, x2, y2);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawLine指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawLine指令失败， 错误代码：" + res);
                }
            }
        #if (false)
            //该接口暂无作用
            if (false)
            {
                /* 调用高级画线指令 */
                short x1 = 1;
                short y1 = 0;
                short x2 = 13;
                short y2 = 12;
                uint color = 0x07;
                res = LedControl.JHDrawLineEx(hdl, x1, y1, x2, y2, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawLineEx指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawLineEx指令失败， 错误代码：" + res);
                }
            }
        #endif
        #if (false)
            //该接口暂无作用
            if (false)
            {
                /* 调用画矩形指令 不完全支持*/
                short x1 = 0;
                short y1 = 0;
                ushort width = 10;
                ushort height = 10;
                res = LedControl.JHFrameRect(hdl, x1, y1, width, height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFrameRect指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHFrameRect指令失败， 错误代码：" + res);
                }
            }
        #endif
        #if (false)
            //该接口暂无作用
            if (false)
            {
                /* 调用高级画矩形指令JHFillRect */
                short x1 = 2;
                short y1 = 2;
                ushort width = 12;
                ushort height = 12;
                uint color = 0x07;
                res = LedControl.JHFrameRectEx(hdl, x1, y1, width, height, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFrameRectEx指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHFrameRectEx指令失败， 错误代码：" + res);
                }
            }
        #endif
            if (false)
            {
                /* 调用填充矩形指令 */
                short x1 = 0;
                short y1 = 0;
                ushort width = 10;
                ushort height = 10;
                res = LedControl.JHFillRect(hdl, x1, y1, width, height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFillRect指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHFillRect指令失败， 错误代码：" + res);
                }
            }
        #if (false)
            //该接口暂无作用
            if (false)
            {
                /* 调用高级填充矩形指令JHFillRectEx */
                short x1 = 2;
                short y1 = 2;
                ushort width = 12;
                ushort height = 12;
                uint color = 0x01;
                res = LedControl.JHFillRectEx(hdl, x1, y1, width, height, color);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFillRectEx指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHFillRectEx指令失败， 错误代码：" + res);
                }
            }
        #endif
            if (false)
            {
                /* 调用立即显示文本指令JHDrawText */
                short x = 0;
                short y = 0;
                ushort width = 64;//注意调用时的宽高值，过小可能导致显示不完整
                ushort height = 16;
                uint format = 0;//具体配置参见手册说明
                string text = richTextBox1.Text.ToString();
                res = LedControl.JHDrawText(hdl, x, y, width, height, format, text);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawText指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawText指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用立即显示图片指令JHDrawBitmap，改指令为调用控制卡预先存储的图片显示出来 */
                ushort bmpID = 1;
                short x = 0;
                short y = 0;
                ushort width = 16;//宽高要与存储位图宽高保持一致
                ushort height = 16;
                uint format = 0;//显示格式，为0表示默认，具体参数含义请参见说明手册。
                LedControl.JHBMPSRC bmpsrc;
                bmpsrc.type = 0;//0：已存储位图，1：内存位图，2：二维码字符串
                bmpsrc.version = 0;
                bmpsrc.size = 2;//
                bmpsrc.pdata = new byte[2];;
                bmpsrc.pdata[0] = (byte)((bmpID >> 8) & 0x0f);
                bmpsrc.pdata[1] = (byte)((bmpID >> 0) & 0x0f);

                res = LedControl.JHDrawBitmap(hdl, x, y, width, height, format, ref bmpsrc);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawBitmap指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawBitmap指令失败， 错误代码：" + res);
                }                
            }
        #if (false)
            //该接口暂无作用
            if (false)
            {
                /* 调用立即显示内存位图指令JHDrawMemBitmap，由于位图图片大小的原因，这了建议使用容量尽量小的位图，比如1bit位图 */
                short x = 0;
                short y = 0;
                ushort width = 32;
                ushort height = 16;
                uint format = 0;//显示格式，为0表示默认，具体参数含义请参见说明手册。
                LedControl.JHBMPINFO bmpinfo;
                byte[] pformatstring = null;
                byte is1bit = 0;
                uint size = 0;//位图图片所占字节数
                BinaryReader br;
                FileInfo fileinfo = new FileInfo("../../../../res/斜点32x16.bmp");

                size = (uint)(fileinfo.Length);
                if (size > 1200)
                {
                    MessageBox.Show("图片文件: 斜点32x16.bmp 所占存储空间为" + size + "字节，超过1200字节上限!");
                    goto FLAG_END;
                }
                try
                {
                    br = new BinaryReader(new FileStream("../../../../res/斜点32x16.bmp", FileMode.Open));
                }
                catch (IOException ep)
                {
                    MessageBox.Show(ep.Message + "\n Cannot open file: 斜点32x16.bmp");
                    goto FLAG_END;
                }

                bmpinfo.type = 0;
                bmpinfo.version = 0;
                bmpinfo.size = size;
                pformatstring = br.ReadBytes((int)size);
                br.Close();

                res = LedControl.JHDrawMemBitmap(hdl, x, y, width, height, format, ref bmpinfo, pformatstring, is1bit);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawMemBitmap指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawMemBitmap指令失败， 错误代码：" + res);
                }

            FLAG_END:
                ;

            }
        #endif
            if (false)
            {
                /* 调用立即显示二维码指令JHDrawQRCode，二维码长度不能超过128个字节，具体还要参考不同型号板卡的限制 */
                short x = 0;
                short y = 0;
                ushort width = 32;
                ushort height = 32;
                uint format = 0;//显示格式，为0表示默认，具体参数含义请参见说明手册。
                LedControl.JHBMPINFO bmpinfo;
                string pformatstring = "This is a test text!";
                uint size = (uint)(pformatstring.Length);//二维码长度
 
                bmpinfo.type = 2;
                bmpinfo.version = 0;
                bmpinfo.size = size;

                res = LedControl.JHDrawQRCode(hdl, x, y, width, height, format, ref bmpinfo, pformatstring);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDrawQRCode指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDrawQRCode指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用左移一格指令JHScrollLeft */
                short x = 0;
                short y = 0;
                ushort width = 32;
                ushort height = 16;
                res = LedControl.JHScrollLeft(hdl, x, y, width, height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHScrollLeft指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHScrollLeft指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用右移一格指令JHScrollRight */
                short x = 0;
                short y = 0;
                ushort width = 32;
                ushort height = 16;
                res = LedControl.JHScrollRight(hdl, x, y, width, height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHScrollRight指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHScrollRight指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用上移一格指令JHScrollUp */
                short x = 0;
                short y = 0;
                ushort width = 32;
                ushort height = 16;
                res = LedControl.JHScrollUp(hdl, x, y, width, height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHScrollUp指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHScrollUp指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用下移一格指令JHScrollDown */
                short x = 0;
                short y = 0;
                ushort width = 32;
                ushort height = 16;
                res = LedControl.JHScrollDown(hdl, x, y, width, height);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHScrollDown指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHScrollDown指令失败， 错误代码：" + res);
                }
            }

            /***************************************屏幕操作指令结束*********************************/


            /***************************************分区操作指令开始*********************************/

            if (false)
            {
                /* 调用查询分区数目指令JHGetWndCnt */
                ushort cnt = 0;
                res = LedControl.JHGetWndCnt(hdl, ref cnt);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetWndCnt指令成功，共查询到" + cnt + "个分区。");
                }
                else
                {
                    MessageBox.Show("发送JHGetWndCnt指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询分区编号(ID)指令JHGetWndId */
                ushort index = 0;//分区序号，有效值从0开始
                ushort wid = 0;//分区ID号，有效值从1开始，分区ID与分区需要是有区别的，分区序号为创建分区的先后顺序，而每次创建分区时是可以指定其ID的。
                res = LedControl.JHGetWndId(hdl, index, ref wid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHGetWndId指令成功，第" + index + "个分区的ID为" + wid);
                }
                else
                {
                    MessageBox.Show("发送JHGetWndId指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询分区属性指令JHFingerWnd */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort x = 0;
                ushort y = 0;
                ushort width = 0;
                ushort height = 0;
                uint style = 0;
                uint userdata = 0;
                res = LedControl.JHFingerWnd(hdl, wid, ref x, ref y, ref width, ref height, ref style, ref userdata);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFingerWnd指令成功，ID为" + wid + "的分区属性为：" 
                        + "\nx = " + x
                        + "\ny = " + y 
                        + "\nwidth = " + width 
                        + "\nheight = " + height 
                        + "\nstyle = " + style
                        + " \nuserdata = " + userdata);
                }
                else
                {
                    MessageBox.Show("发送JHFingerWnd指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建分区指令JHCreateWnd */
                ushort wid = 3;//分区ID号，有效值从1开始
                ushort option = 0;
                ushort x = 0;
                ushort y = 0;
                ushort width = 32;
                ushort height = 16;
                uint style = 0;//临时分区，2为永久分区
                uint userdata = 0;
                res = LedControl.JHCreateWnd(hdl, wid, option, x, y, width, height, style, userdata);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateWnd指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateWnd指令失败， 错误代码：" + res);//注意如果分区ID超过最大分区或者已经存在了，可能会创建失败，具体需要看style参数。
                }
            }

            if (false)
            {
                /* 调用修改分区属性指令JHChangeWnd */
                ushort wid = 3;//分区ID号，有效值从1开始
                ushort x = 0;
                ushort y = 0;
                ushort width = 32;
                ushort height = 16;
                uint style = 2;//永久分区
                uint userdata = 0;
                res = LedControl.JHChangeWnd(hdl, wid, x, y, width, height, style, userdata);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHChangeWnd指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHChangeWnd指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用删除分区指令JHDeleteWnd */
                ushort wid = 3;//分区ID号，有效值从1开始
                  res = LedControl.JHDeleteWnd(hdl, wid);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDeleteWnd指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDeleteWnd指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用控制分区播放状态指令JHWndPlayCtrl */
                ushort wid = 1;//分区ID号，有效值从1开始
                byte stat = 0;//0为停止播放，1为开始播放
                res = LedControl.JHWndPlayCtrl(hdl, wid, stat);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHWndPlayCtrl指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHWndPlayCtrl指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用查询分区播放进度指令JHGetProgress */
                ushort wid = 1;//分区ID号，有效值从1开始
                uint curtime = 0;
                uint totaltime = 0;
                res = LedControl.JHGetProgress(hdl, wid, ref curtime, ref totaltime);
                if (res == LedControl.JR_OK)
                {//如果节目是一直循环的节目，总的播放时间会是0xffffffff
                    MessageBox.Show("发送JHGetProgress指令成功，当前播放进度" + curtime + "毫秒，总时长" + totaltime + "毫秒。");
                }
                else
                {
                    MessageBox.Show("发送JHGetProgress指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建分区文本节目指令JHCreateTextProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                LedControl.JHTEXTPROG textprog;
                textprog.tpEntryMode = 0;
                textprog.tpEntrySpeed = 0;
                textprog.tpEntryStaytime = 100;
                textprog.tpHighLightMode = 0;
                textprog.tpHighLightSpeed = 0;
                textprog.tpHighLightStaytime = 0;
                textprog.tpExitMode = 0;
                textprog.tpExitSpeed = 0;
                textprog.tpRepeatTimes = 0;
                string text = richTextBox1.Text.ToString();
                res = LedControl.JHCreateTextProg(hdl, wid, rev, style, format, ref textprog, text);
                if (res == LedControl.JR_OK)
                {
                    //注意style和format各个位代表的含义
                    MessageBox.Show("发送JHCreateTextProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateTextProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建图片节目指令JHCreateBitmapProg */
                byte bmpID = 1;//图片要事先预存到控制卡中
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                LedControl.JHTEXTPROG textprog;
                textprog.tpEntryMode = 0;
                textprog.tpEntrySpeed = 0;
                textprog.tpEntryStaytime = 100;
                textprog.tpHighLightMode = 0;
                textprog.tpHighLightSpeed = 0;
                textprog.tpHighLightStaytime = 0;
                textprog.tpExitMode = 0;
                textprog.tpExitSpeed = 0;
                textprog.tpRepeatTimes = 0;
                ushort rev2 = 0;
                LedControl.JHBMPSRC bmpsrc;
                bmpsrc.type = 0;
                bmpsrc.version = 0;
                bmpsrc.size = 2;
                bmpsrc.pdata = new byte[2]; ;
                bmpsrc.pdata[0] = (byte)((bmpID >> 8) & 0x0f);
                bmpsrc.pdata[1] = (byte)((bmpID >> 0) & 0x0f);

                res = LedControl.JHCreateBitmapProg(hdl, wid, rev, style, format, ref textprog, rev2, ref bmpsrc);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateBitmapProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateBitmapProg指令失败， 错误代码：" + res);
                }
            }
        #if (false)
            //暂不支持
            if (false)
            {
                /* 调用创建内存位图节目指令JHCreateMemBitmapProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                LedControl.JHTEXTPROG textprog;
                textprog.tpEntryMode = 0;
                textprog.tpEntrySpeed = 0;
                textprog.tpEntryStaytime = 100;
                textprog.tpHighLightMode = 0;
                textprog.tpHighLightSpeed = 0;
                textprog.tpHighLightStaytime = 0;
                textprog.tpExitMode = 0;
                textprog.tpExitSpeed = 0;
                textprog.tpRepeatTimes = 0;
                string text = richTextBox1.Text.ToString();
                ushort rev2 = 0;
                LedControl.JHBMPINFO bmpinfo;
                bmpinfo.type = 0;
                bmpinfo.version = 0;
                bmpinfo.size = 0;
                byte[] data = new byte[20];
                byte is1bit = 0;
                res = LedControl.JHCreateMemBitmapProg(hdl, wid, rev, style, format, ref textprog, rev2, ref bmpinfo, data, is1bit);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateMemBitmapProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateMemBitmapProg指令失败， 错误代码：" + res);
                }
            }
        #endif
            if (false)
            {
                /* 调用创建二维码节目指令JHCreateQRCodeProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                LedControl.JHTEXTPROG textprog;
                textprog.tpEntryMode = 0;
                textprog.tpEntrySpeed = 0;
                textprog.tpEntryStaytime = 100;
                textprog.tpHighLightMode = 0;
                textprog.tpHighLightSpeed = 0;
                textprog.tpHighLightStaytime = 0;
                textprog.tpExitMode = 0;
                textprog.tpExitSpeed = 0;
                textprog.tpRepeatTimes = 0;
                ushort rev2 = 0;

                LedControl.JHBMPINFO bmpinfo;
                string text = "This is a test text!";
                uint size = (uint)(text.Length);//二维码长度

                bmpinfo.type = 2;
                bmpinfo.version = 0;
                bmpinfo.size = size;

                res = LedControl.JHCreateQRCodeProg(hdl, wid, rev, style, format, ref textprog, ref bmpinfo, text);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateQRCodeProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateQRCodeProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建简易时钟节目指令JHCreateSimpleDigClockProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                uint timeoffset = 0;
                res = LedControl.JHCreateSimpleDigClockProg(hdl, wid, rev, style, format, timeoffset);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateSimpleDigClockProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateSimpleDigClockProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建数字时钟节目指令JHCreateDigClockProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                uint timeoffset = 0;
                string text = "%yyyy-%MM-%dd %HH:%mm:%ss";
                res = LedControl.JHCreateDigClockProg(hdl, wid, rev, style, format, timeoffset, text);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateDigClockProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateDigClockProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建高级数字时钟节目指令JHCreateComplexDigClockProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                uint timeoffset = 0;
                LedControl.JHTEXTPROG textprog;
                textprog.tpEntryMode = 0;
                textprog.tpEntrySpeed = 0;
                textprog.tpEntryStaytime = 100;
                textprog.tpHighLightMode = 0;
                textprog.tpHighLightSpeed = 0;
                textprog.tpHighLightStaytime = 0;
                textprog.tpExitMode = 0;
                textprog.tpExitSpeed = 0;
                textprog.tpRepeatTimes = 0;
                string text = "%yyyy-%MM-%dd %HH:%mm:%ss";
                res = LedControl.JHCreateComplexDigClockProg(hdl, wid, rev, style, format, timeoffset, ref textprog, text);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateComplexDigClockProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateComplexDigClockProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建倒计时节目指令JHCreateCountdownProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                uint timeoffset = 0;
                uint flag = 0;
                LedControl.JHSYSTEMTIME time;
                time.wYear = 2030;
                time.wMonth = 1;
                time.wDay = 1;
                time.wHour = 0;
                time.wMinute = 0;
                time.wSecond = 0;
                time.wDayOfWeek = 0;
                time.wMilliseconds = 0;
                string text = "%D天%h时%m分%s秒";
                res = LedControl.JHCreateCountdownProg(hdl, wid, rev, style, format, timeoffset, flag, ref time, text);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateCountdownProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateCountdownProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用创建正计时节目指令JHCreateCountupProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort rev = 0;
                uint style = 0;
                uint format = 0;
                uint timeoffset = 0;
                uint flag = 0;
                LedControl.JHSYSTEMTIME time;
                time.wYear = 2020;
                time.wMonth = 1;
                time.wDay = 1;
                time.wHour = 0;
                time.wMinute = 0;
                time.wSecond = 0;
                time.wDayOfWeek = 0;
                time.wMilliseconds = 0;
                string text = "%D天%h时%m分%s秒";
                res = LedControl.JHCreateCountupProg(hdl, wid, rev, style, format, timeoffset, flag, ref time, text);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHCreateCountupProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHCreateCountupProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用获取默认节目指令JHFingerProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort option = 0;
                ushort rev = 0;
                ushort type = 0;
                uint style = 0;
                byte[] dat = new byte[1200];//最大1200字节
                ushort size = 1200;
                
                res = LedControl.JHFingerProg(hdl, wid, option, ref rev, ref type, ref style, dat, ref size);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHFingerProg指令成功:" + 
                                    "\r\nrev = " + rev + 
                                    "\r\ntype = " + type + 
                                    "\r\nstyle = " + style + 
                                    "\r\nsize = " + size);
                }
                else
                {
                    MessageBox.Show("发送JHFingerProg指令失败， 错误代码：" + res);
                }
            }

            if (false)
            {
                /* 调用删除分区节目指令JHDeleteProg */
                ushort wid = 1;//分区ID号，有效值从1开始
                ushort option = 0;
                res = LedControl.JHDeleteProg(hdl, wid, option);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHDeleteProg指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHDeleteProg指令失败， 错误代码：" + res);
                }
            }

            /***************************************分区操作指令结束*********************************/

            
            
            
            /***************************************批处理操作指令结束*********************************/



            /***************************************批处理操作指令结束*********************************/




            /****************************************************************/
            if (false)
            {
                /* 调用开始合成语音指令JHSpeechSynthesisStart */
                string text = richTextBox1.Text.ToString();
                res = LedControl.JHSpeechSynthesisStart(hdl, 0, (ushort)text.Length, text);
                if (res == LedControl.JR_OK)
                {
                    MessageBox.Show("发送JHSpeechSynthesisStart指令成功");
                }
                else
                {
                    MessageBox.Show("发送JHSpeechSynthesisStart指令失败， 错误代码：" + res);
                }
            }
            /***************************************************************/
        #endif

            /* 删除控制卡实例 */
            LedControl.JHDeleteInst(hdl);
        }
        
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            /* 清理jinhan comm库 */
            LedControl.JHCommDeinit();
        }
    }
}
